home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / KEYBOARD.SWG / 0002_Re: keyboard buffer routines.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  2.3 KB  |  100 lines

  1.  
  2. {
  3. GA> To clear the keyboard buffer
  4. GA>
  5. GA> To manipulate the status of the num lock, caps lock, and scroll lock keys
  6.  
  7. To flush the keyboard, you can do it like this: }
  8.  
  9. procedure flushkb; assembler;
  10. asm
  11.   mov ax,0c00h
  12.   int 21h
  13. end;
  14.  
  15. or simply use a "mem[$0000:$041c]:=mem[$0000:$041a];" command.  To toggle the
  16. status of the number lock, caps lock, and scroll lock keys, the following
  17. procedures can be used.
  18.  
  19. procedure capslock(on:boolean);
  20. begin
  21.   if on then mem[$40:$17]:=mem[$40:$17] or $40
  22.     else
  23.   mem[$40:$17]:=mem[$40:$17] and $bf;
  24. end;
  25.  
  26. procedure numlock(on:boolean);
  27. begin
  28.   if on then mem[$40:$17]:=mem[$40:$17] or $20
  29.     else
  30.   mem[$40:$17]:=mem[$40:$17] and $df;
  31. end;
  32.  
  33. procedure scrolllock(on:boolean);
  34. begin
  35.   if on then mem[$40:$17]:=mem[$40:$17] or $10
  36.     else
  37.   mem[$40:$17]:=mem[$40:$17] and $ef;
  38. end;
  39.  
  40. ... If you need routines to detect whether the caps/scroll/number lock keys
  41. are on or off, these may be of use ...
  42.  
  43. function capslockon:boolean;
  44. begin
  45.   capslockon:=mem[$0040:$0017] and $40=$40;
  46. end;
  47.  
  48. function numlockon:boolean;
  49. begin
  50.   numlockon:=mem[$0040:$0017] and $20=$20;
  51. end;
  52.  
  53. function scrollockon:boolean;
  54. begin
  55.   scrollockon:=mem[$0040:$0017] and $10=$10;
  56. end;
  57.  
  58. {
  59. AN> im looking to make my own keypress/readkey routines, simply because
  60. AN> of the  fact that readkey does all that keyboard aliasing (#0 leading a
  61. AN> keypress, and  that #0 = alt and ctrl, etc).. does anyone have any
  62. AN> routines that can help?
  63.  
  64. Try this on for size... instead of returning a character, it'll return a
  65. word.  The high portion of the word contains the scan code (the one you
  66. get after doing a second readkey if the first returned #0) and the lower
  67. portion of the word contains the ascii code.
  68. }
  69.  
  70. function getkey:word; assembler;
  71. asm
  72.   mov ah,10h
  73.   int 16h
  74.   cmp al,0e0h
  75.   jne @end
  76.   mov al,00h
  77.   @end:
  78. end;
  79.                   { usage example ... }
  80. var w:word;
  81.  
  82. begin
  83.   w:=getkey;
  84.   if hi(w)=0 then case lo(w) of
  85.     59:write('F1');
  86.     60:write('F2');
  87.     61:write('F3');
  88.     62:write('F4');
  89.     63:write('F5'); { etc ... }
  90.   end else case chr(lo(w)) of
  91.     '1':write('Pressed 1');
  92.     '2':write('Pressed 2');
  93.     '3':write('Pressed 3');
  94.     'A':write('Pressed A');
  95.     'B':write('Pressed B');
  96.     'C':write('Pressed C');
  97.   end;
  98. end.
  99.  
  100.